/*
 * =====================================================================================
 *
 *       Filename:  Bridge.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2015年02月26日 22时24分00秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  LiuYi (), swliuyi@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <limits.h>
#include <iostream>
#include  <memory>

using namespace std;

class Implementor
{
    public:
        virtual void Operation() = 0;
};

class ConcreteImplementorA : public Implementor
{
    public:
        void Operation()
        {
            cout<<"A is Implementor"<<endl;
        }
};

class ConcreteImplementorB : public Implementor
{
    public:
        void Operation()
        {
            cout<<"B is Implementor"<<endl;
        }
};

class Abstraction
{
    protected:
        shared_ptr<Implementor> m_implementor;
    public:
        void SetImplementor(Implementor * implementor)
        {
            m_implementor.reset(implementor);
        }
        virtual void Operation()
        {
            m_implementor->Operation();
        }
};

class RefinedAbstraction : public Abstraction
{
    public:
        void Operation()
        {
            m_implementor->Operation();
        }
};

int main(int argc, char *argv[])
{
    shared_ptr<Abstraction> ab(new RefinedAbstraction());

    ab->SetImplementor(new ConcreteImplementorA());
    ab->Operation();

    ab->SetImplementor(new ConcreteImplementorB());
    ab->Operation();
}
